/*
** my_square_root.c for my_square_root in /home/goupil_r//afs/local/Jour_05
**
** Made by robin goupil
** Login   <goupil_r@epitech.net>
**
** Started on  Fri Oct  5 18:37:50 2012 robin goupil
** Last update Tue Nov  6 10:43:24 2012 robin goupil
*/

int	my_square_root(int nb)
{
  double        s;
  int           d;
  int           n_bis;

  s = 0;
  d = 0;
  n_bis = nb;
  while (n_bis > 0)
    {
      if (n_bis > 0)
	d = d + 1;
      n_bis = n_bis / 10;
    }
  s = 10 * d;
  n_bis = 0;
  while (n_bis < 5 * d)
    {
      s = 0.5 * (s + (nb / s));
      n_bis = n_bis + 1;
    }
  if ((s - (int)s > 0.01 && s - (int)s < 0.09) || nb < 4 || nb > 2147395600)
    return (0);
  return ((int)s);
}
